# JSAnimation import available at https://github.com/jakevdp/JSAnimation
%pylab inline
from JSAnimation import IPython_display
from matplotlib import animation
# create a simple animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 10), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
x = np.linspace(0, 10, 1000)
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_data(x, np.cos(i * 0.02 * np.pi) * np.sin(x - i * 0.02 * np.pi))
return line,
animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
# JSAnimation import available at https://github.com/jakevdp/JSAnimation
from JSAnimation import IPython_display
from matplotlib import animation
# create a simple animation
fig = plt.figure()
ax = plt.axes(xlim=(0, 10), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)
x = np.linspace(0, 10, 1000)
def init():
line.set_data([], [])
return line,
def animate(i):
line.set_data(x, np.cos(i * 0.02 * np.pi) * np.sin(x - i * 0.02 * np.pi))
return line,
animation.FuncAnimation(fig, animate, init_func=init,
frames=100, interval=20, blit=True)
import numpy as np
from math import *
from pylab import *
from matplotlib import pyplot as plt
from matplotlib import animation
def generate(X, Y, phi):
R = 1 - np.sqrt(X**2 + Y**2)
return np.cos(2 * np.pi * X + phi) * R
# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax1 = plt.subplot(131)
ax2 = plt.subplot(132,projection='3d')
line, = ax1.plot([], [], lw=2, color='b')
x = np.linspace(0, 10, 1000)
line.set_data(x, np.cos(0) * np.sin(x ))
xs = np.linspace(-1, 1, 50)
ys = np.linspace(-1, 1, 50)
X, Y = np.meshgrid(xs, ys)
Z = generate(X, Y, 0.0)
scat = ax2.plot_wireframe(X, Y, Z, rstride=2, cstride=2)
ax2.set_zlim(-1,1)
# animation function. This is called sequentially
def animate(i):
line.set_data(x, np.cos(i * 0.02 * np.pi) * np.sin(x - i * 0.02 * np.pi))
ax2.cla()
phi = i * 360 / 2 / np.pi / 100
Z = generate(X, Y, phi)
scat = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2)
ax2.set_zlim(-1,1)
return [scat,line,]
# call the animator.
animation.FuncAnimation(fig, animate,
frames=100, interval=20, blit=True)
# plt.show()
c = demo.cost_history
from mpl_toolkits.mplot3d import axes3d
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from JSAnimation import IPython_display
def generate(X, Y, phi):
R = 1 - np.sqrt(X**2 + Y**2)
return np.cos(2 * np.pi * X + phi) * R
fig = plt.figure(num=None, figsize=(12,4), dpi=80, facecolor='w', edgecolor='k')
ax1 = plt.subplot(131)
ax2 = plt.subplot(132,projection='3d')
ax3 = plt.subplot(133)
# ax = axes3d.Axes3D(fig)
x = np.linspace(0,2*np.pi,100)
y = np.sin(x)
# line = ax1.plot(x,y)
# line2 = ax3.plot(x,y)
xs = np.linspace(-1, 1, 50)
ys = np.linspace(-1, 1, 50)
X, Y = np.meshgrid(xs, ys)
Z = generate(X, Y, 0.0)
# wframe = ax2.plot_surface(X, Y, Z, rstride=2, cstride=2)
# ax2.set_zlim(-1,1)
blah = np.sin(x)
def update(i):
# make top panel
ax1.cla()
ax3.cla()
y = np.sin(i*x)
ax1.plot(x,y)
ax3.plot(x,y)
# make middle panel
ax2.cla()
phi = i * 360 / 2 / np.pi / 100
Z = generate(X, Y, phi)
wframe = ax2.plot_surface(X, Y, Z, rstride=2, cstride=2)
ax2.scatter(x[i],blah[i],1)
ax2.set_zlim(-1,1)
return wframe,
animation.FuncAnimation(fig, update,frames=100, interval=100, blit=True)
# ani = animation.FuncAnimation(fig, update,
# frames=xrange(100),
# fargs=(ax, fig), interval=100)
# plt.show()